package com.longrise.android.byjk.plugins.aboutme.personalInfo.request;

import android.content.Context;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.common.datasource.remote.LoadDataManager;
import com.longrise.common.utils.PrintLog;

/**
 * Created by sujizhong on 2016/12/13.
 * <p>
 * 请求数据
 */

public class PersionRequest {

    private static final String TAG = "PersionRequest";

    private BaseRequestResult mResult = null;

    public PersionRequest(BaseRequestResult result) {
        this.mResult = result;
    }

    public void setResult(BaseRequestResult result) {
        this.mResult = result;
    }

    public void request(Context cxt, String reqeustUrl, EntityBean requestBean) {

        PrintLog.e(TAG, "request");

        LoadDataManager.getInstance().callService(null, UrlConstants.BaseUrl, reqeustUrl, requestBean, new LoadDataManager.OnRequestCallListener() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    if (mResult != null) {
                        mResult.onSuccess((EntityBean) result);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished(String key, String service) {
                if (mResult != null) {
                    mResult.onFinish();
                }
            }

            @Override
            public void onError(String key, String service, Throwable ex, boolean isOnCallback) {
                if (mResult != null) {
                    mResult.onFailure(key);
                }
            }
        });
    }
}
